<template>
    <view class="page-box">
        <view class="order_addcart_detail">
            <view class="base-info">
                <view class="input-box row bothSide verCenter">
                    <text class="label">客户姓名</text>
                    <text class="tt">{{detail.apply_name}}</text>
                </view>
                <view class="input-box row bothSide verCenter">
                    <text class="label">进件时间</text>
                    <text class="tt">{{detail.create_time}}</text>
                </view>
                <view class="input-box row bothSide verCenter">
                    <text class="label">所属渠道</text>
                    <text class="tt">{{detail.channel_user_name}}</text>
                </view>
            </view>
            <view class="info">
                <view class="input-box row bothSide verCenter">
                    <text class="label">授信金额</text>
                    <text class="tt">{{detail.credit_amount}}</text>
                </view>
                <view class="input-box row bothSide verCenter">
                    <text class="label">放款金额</text>
                    <text class="tt">{{detail.lending_amount}}</text>
                </view>
                <view class="input-box row bothSide verCenter">
                    <text class="label">进件状态</text>
                    <text class="tt">{{detail.status_val}}</text>
                </view>
            </view>
            <view class="progress">
                <view class="title">审核进度</view>
                <view class="progress-list" :class="{'progress-diabled':detail.status == -1}">
                    <view class="box row" v-for="(item,index) in business_progress" :key="index">
                        <text class="line"></text>
                        <template v-if="item.business_status_val">
                            <text class="iconfont icon-gouxuan"></text>
                        </template>
                        <template v-else>
                            <text class="iconfont icon-gouxuan1"></text>
                        </template>
                        <view class="text">
                            <view class="p1">
                                <text class="t1">{{item.business_progress_val}}</text>
                                <text class="t2">{{item.create_time}}</text>
                            </view>
                            <view class="p2">{{ item.node_desc }}</view>
                        </view>
                    </view>
                </view>
            </view>
            <view class="info">
                <view class="input-box row bothSide verCenter">
                    <text class="label">进件单号</text>
                    <text class="text">{{detail.order_sn}}</text>
                </view>
                <view class="input-box row bothSide verCenter">
                    <text class="label">更新时间</text>
                    <text class="text">{{detail.update_time}}</text>
                </view>
            </view>
        </view>
        <watermark :name="name" :phoneLastDigits="phoneLastDigits" />
    </view>
</template>

<script>
    import { API } from '@/util/api.js';
    import watermark from '@/components/watermark/watermark.vue';

    export default {
        components: {
            watermark
        },
        data() {
            return {
                detail: {},
                order_id: '',
                name: '',
                phoneLastDigits: '',
                business_progress: [{
                    business_progress_val: '申请中',
                    create_time: '',
                    business_status_val: '',
                    node_desc: ''
                }, {
                    business_progress_val: '初审中',
                    create_time: '',
                    business_status_val: '',
                    node_desc: ''
                }, {
                    business_progress_val: '进件中',
                    create_time: '',
                    business_status_val: '',
                    node_desc: ''
                }, {
                    business_progress_val: '审批中',
                    create_time: '',
                    business_status_val: '',
                    node_desc: ''
                }, {
                    business_progress_val: '签约中',
                    create_time: '',
                    business_status_val: '',
                    node_desc: ''
                }, {
                    business_progress_val: '放款中',
                    create_time: '',
                    business_status_val: '',
                    node_desc: ''
                }, {
                    business_progress_val: '结算中',
                    create_time: '',
                    business_status_val: '',
                    node_desc: ''
                }]
            };
        },
        onLoad(options) {
            this.order_id = options.order_id;
        },
        onShow() {
            this.getData();
        },
        methods: {
            getData() {
                this.request(API.getUserInfo, 'GET', {}, false).then(res => {
                    if (res.code === 0) {
                        this.name = res.data.name;
                        // 截取电话号码的后4位
                        this.phoneLastDigits = res.data.tel.slice(-4);
                    }
                });
                this.request(API.orderDetail, 'GET', { order_id: this.order_id }, true).then(res => {
                    if (res.code === 0) {
                        this.detail = res.data;
                        uni.setNavigationBarTitle({
                            title: res.data.product_name + ' - 进件详情'
                        });

                        // 遍历data数组并更新business_progress中的相应对象
                        this.detail.business_progress_list.forEach(item => {
                            let progress = this.business_progress.find(bp => bp.business_progress_val === item.business_progress_val);
                            if (progress) {
                                progress.create_time = item.create_time;
                                progress.business_status_val = item.business_status_val;
                                progress.node_desc = item.node_desc;
                            }
                        });

                    } else {
                        uni.showToast({
                            title: res.msg,
                            icon: 'none'
                        });
                    }
                });
            }
        }
    };
</script>

<style scoped lang="scss">
    @import '@/assets/css/order/detail.scss';
</style>